package com.atguigu.day07;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Flink04_Union {
    public static void main(String[] args) throws Exception {
        //1.获取流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        //2.从元素中获取数据
        DataStreamSource<String> numStream = env.fromElements("1", "2", "3", "4", "5");

        DataStreamSource<String> strStream = env.fromElements("a", "b", "c", "d", "e");

        //TODO 3.使用union将多条流合并到一起
        DataStream<String> union = numStream.union(strStream);

        union.map(new MapFunction<String, String>() {
            @Override
            public String map(String value) throws Exception {
                return value + "aaaaaa";
            }
        }).print();


        env.execute();


    }
}
